package com.mt.system.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.system.entity.AppVersionEntity;
import com.mt.system.mapper.AppVersionEntityMapper;

@Component
public class AppVersionServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AppVersionServiceModel.class);

    @Autowired
    private AppVersionEntityMapper appVersionEntityMapper;

    public ServiceResult<List<AppVersionEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.appVersionEntityMapper, "Property 'appVersionEntityMapper' is required.");
        ServiceResult<List<AppVersionEntity>> result = new ServiceResult<List<AppVersionEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.appVersionEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[SupplierImageServiceImpl][findList]：query findList occur exception", e);
        }
        return result;
    }

    public ServiceResult<AppVersionEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.appVersionEntityMapper, "Property 'appVersionEntityMapper' is required.");
        ServiceResult<AppVersionEntity> result = new ServiceResult<AppVersionEntity>();
        try {
            result.setResult(this.appVersionEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[AppVersionServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(AppVersionEntity appVersionEntity) {
        Assert.notNull(this.appVersionEntityMapper, "Property 'appVersionEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.appVersionEntityMapper.insert(appVersionEntity);
            if (save > 0) {
                id = appVersionEntity.getAppVersionId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[AppVersionServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(AppVersionEntity appVersionEntity) {
        Assert.notNull(this.appVersionEntityMapper, "Property 'appVersionEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.appVersionEntityMapper.updateByPrimaryKeySelective(appVersionEntity);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[AppVersionServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer appVersionId) {
        Assert.notNull(this.appVersionEntityMapper, "Property 'appVersionEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        Map<String, Object> params = null;
        try {
            int save = this.appVersionEntityMapper.deleteByPrimaryKey(appVersionId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[AppVersionServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
